﻿using Resolve.Contracts;
using Resolve.FlagInfo;
using Resolve.Web;

namespace Resolve
{
    /// <summary>
    /// 编译文件
    /// </summary>
    public class ResolveEngineForFile : ResolveEngineBase
    {
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        public override string Resolve(string filePath)
        {
            FilePath = filePath;
            CheckFilePath();
            FlagCodeInFile flagCodeInFile = CodeCompiler.CompileFile(FilePath, ViewData, Model);
            ViewPageBase viewPageBase = (ViewPageBase)flagCodeInFile.CompileObject;
            //设置Layout数据
            if (!string.IsNullOrEmpty(viewPageBase.Layout))
            {
                ViewPageBase viewPageBaseLayout = (ViewPageBase)viewPageBase.LayoutFlagCodeInFile.CompileObject;
                viewPageBaseLayout.ViewData = ViewData;
                viewPageBaseLayout.Model = Model;
                viewPageBase.LayoutFlagCodeInFile.CompileObject = viewPageBaseLayout;
            }
            HtmlGenerater.FlagCodeInFile = flagCodeInFile;
            string html = HtmlGenerater.Generate();
            return html;
        }
    }
}
